<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <script src="../js/jquery-3.6.0.min.js"></script>
    <style>
        .header {
            width: 1226px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            margin: 0 auto;
        }

        .nav {
            display: flex;
        }

        .nav>li {
            flex: 1;
            border: 1px solid #333;
            position: relative;
        }

        .nav .active {
            background-color: pink;
            color: #fff;
        }

        .nav>li+li {
            border-left: 0;
        }

        .nav>li>a {
            display: block;
            /* padding: 0 20px; */
        }

        .nav>li>.subNav {
            width: 100%;
            position: absolute;
            left: 0;
            top: 40px;
            color: #333;
            border: 1px solid #333;
            border-top: 0;
            margin-left: -1px;
            display: none;
        }
    </style>
</head>

<body>
    <div>
        全选:
        <input type="checkbox" name="" id="" class="check-all">
    </div>
    <div>
        单选:
        <input type="checkbox" name="" id="" class="check-one">
        <input type="checkbox" name="" id="" class="check-one">
        <input type="checkbox" name="" id="" class="check-one">
        <input type="checkbox" name="" id="" class="check-one">
        <input type="checkbox" name="" id="" class="check-one">
        <input type="checkbox" name="" id="" class="check-one">
    </div>
</body>
<script>

    $(".check-all").click(function () {
        // 全选状态
        // var status = this.checked;  // 原生(元素节点的属性)

        var status = $(this).prop("checked");
        console.log(status);

        $(".check-one").prop("checked", status);
    })

    $(".check-one").click(function () {
        // 是否反选
        // 选中单选框 和 所有的单选数量相同

        //  $(".check-one:checked")  选中状态的check-one
        var flag = $(".check-one:checked").length === $(".check-one").length ? true : false;
        flag = $(".check-one").length > 0 ? flag : false;

        $(".check-all").prop("checked", flag);

    })


</script>

</html>